package com.zero.dubbo.sample.echo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.zero.dubbo.sample.api.EchoService;
import com.zero.dubbo.sample.provider.EchoServiceImpl;


import java.io.IOException;

public class EchoProvider {

    public static void main(String[] args) throws IOException {

        //服务实现
        EchoServiceImpl echoService = new EchoServiceImpl();

        //当前应用配置
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("java-echo-provider");
        applicationConfig.setVersion("1.0.0");
        applicationConfig.setOwner("wql");

       //连接注册中心
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://192.168.0.239:2181");

        applicationConfig.setRegistry(registryConfig);
        //协议
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(12345);
        protocolConfig.setThreads(200);

        ServiceConfig<EchoService> service = new ServiceConfig<>();
        service.setApplication(applicationConfig);
        //service.setRegistry(registryConfig);
        service.setProtocol(protocolConfig);
        service.setInterface(EchoService.class);
        service.setRef(new EchoServiceImpl());
        //暴露服务
        service.export();
        System.out.println("java-echo-provider is running");
        System.in.read();
    }
}
